package com.acme.bankapp.service.bank;


import com.acme.bankapp.domain.bank.client.Client;

public class EmailService {

    public Queue queue;
    private EmailSender _emailSender;

    public EmailService() {

        queue = new Queue();
        _emailSender = new EmailSender(queue);
    }

    public void sendNotificationEmail(Client client, String emailAddress) {

        if (client == null || emailAddress == null || emailAddress.equals("")) {
            return;
        }
        Email email = new Email();
        email.client = client;
        email.emailAddress = emailAddress;
        queue.add(email);
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
        }
    }

    public void close() {
        queue.isClosed = true;
        try {
            this._emailSender.thread.join();
        } catch (InterruptedException e) {
        }

    }

}
